package com.example.zhxy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zhxy.pojo.Grade;
import com.example.zhxy.service.GradeService;
import com.example.zhxy.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * CJ
 */
@Api(tags = "年纪控制器")
@RestController
@RequestMapping("/sms/gradeController")
public class GradeController {
    @Autowired
    private GradeService gradeService;
    @ApiOperation("分页功能")
    @GetMapping("/getGrades/{pageNo}/{pageSize}")
    public Result page(@PathVariable("pageNo") Integer pageNo,
                       @PathVariable("pageSize") Integer pageSize,
                       String gradeName){
        Page<Grade> page=new Page(pageNo,pageSize);
        IPage<Grade> iPage=gradeService.Ipage(page,gradeName);
        return Result.ok(page);
    }

    @ApiOperation("新增或修改功能")
    @PostMapping("/saveOrUpdateGrade")
    public Result saveOrUpdateGrade(@RequestBody Grade grade){
        //有id进行修改
        boolean b = gradeService.saveOrUpdate(grade);
        if(b){
            return Result.ok();
        }else return Result.fail().message("新增或修改失败");
    }

    @ApiOperation("批量删除功能")
    @DeleteMapping("/deleteGrade")
    public Result deleteGrade(@RequestBody List<Integer> list){
        boolean b = gradeService.removeByIds(list);
        if(b){
            return Result.ok();
        }else return Result.fail().message("删除失败");

    }
    @ApiOperation("获取所以年纪信息")
    @GetMapping("/getGrades")
    public Result getGrades(){
        List<Grade> list=gradeService.getGrade();
        return Result.ok(list);

    }
}
